package com.ss.android.article.base.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

import java.util.ArrayDeque;
import java.util.Queue;

public class BrowserProgressBar extends View {
    final class a extends Animation {
        private final BrowserProgressBar d;
        private int a;
        private int b;
        private int c;

        a(BrowserProgressBar arg1, int arg2, int arg3, int arg4) {
            this.d = arg1;
            this.a = arg2;
            this.b = arg3;
            this.c = arg4;
        }

        protected final void applyTransformation(float arg5, Transformation arg6) {
            int v0 = this.a + (((int) ((((float) this.b)) * arg5)));
            if (v0 <= this.c) {
                BrowserProgressBar.a(this.d, v0);
                this.d.invalidate();
            }

            if ((((double) Math.abs(1f - arg5))) < 0.00001) {
                if (BrowserProgressBar.a(this.d) >= 100) {
                    BrowserProgressBar.b(this.d);
                }

                if (BrowserProgressBar.c(this.d).isEmpty()) {
                    return;
                }

                this.d.startAnimation((Animation) BrowserProgressBar.c(this.d).poll());
            }
        }

        public final boolean willChangeBounds() {
            return false;
        }

        public final boolean willChangeTransformationMatrix() {
            return false;
        }
    }

    private final Interpolator a;
    private final Interpolator b;
    private final Queue c;
    private final Paint d;
    private final Rect e;
    private int f;
    private boolean g;
    private int h;
    private int i;

    public BrowserProgressBar(Context arg3, AttributeSet arg4) {
        super(arg3, arg4);
        this.a = new LinearInterpolator();
        this.b = new i();
        this.c = new ArrayDeque();
        this.d = new Paint();
        this.e = new Rect();
        this.f = 0;
        this.g = true;
        this.h = 0;
        this.a(arg3, arg4);
    }

    public BrowserProgressBar(Context arg3, AttributeSet arg4, int arg5) {
        super(arg3, arg4, arg5);
        this.a = new LinearInterpolator();
        this.b = new i();
        this.c = new ArrayDeque();
        this.d = new Paint();
        this.e = new Rect();
        this.f = 0;
        this.g = true;
        this.h = 0;
        this.a(arg3, arg4);
    }

    private void a(Context arg4, AttributeSet arg5) {
        TypedArray v1 = arg4.getTheme().obtainStyledAttributes(arg5, com.ss.android.article.base.a.e, 0, 0);
        try {
            this.i = v1.getColor(com.ss.android.article.base.a.g, -65536);
            this.g = v1.getBoolean(com.ss.android.article.base.a.f, false);
        } catch (Throwable v0) {
            v1.recycle();
            throw v0;
        }

        v1.recycle();
    }

    static int a(BrowserProgressBar arg1) {
        return arg1.f;
    }

    static int a(BrowserProgressBar arg0, int arg1) {
        arg0.h = arg1;
        return arg1;
    }

    private void a() {
        this.animate().alpha(0f).setDuration(200).setInterpolator(this.a).start();
    }

    static void b(BrowserProgressBar arg0) {
        arg0.a();
    }

    static Queue c(BrowserProgressBar arg1) {
        return arg1.c;
    }

    public int getProgress() {
        return this.f;
    }

    protected void onDraw(Canvas arg4) {
        this.d.setColor(this.i);
        this.d.setStrokeWidth(10f);
        this.e.right = this.e.left + this.h;
        arg4.drawRect(this.e, this.d);
    }

    protected void onRestoreInstanceState(Parcelable arg2) {
        if ((arg2 instanceof Bundle)) {
            this.f = ((Bundle) arg2).getInt("progressState");
            arg2 = ((Bundle) arg2).getParcelable("instanceState");
        }

        super.onRestoreInstanceState(arg2);
    }

    protected Parcelable onSaveInstanceState() {
        Bundle v0 = new Bundle();
        v0.putParcelable("instanceState", super.onSaveInstanceState());
        v0.putInt("progressState", this.f);
        return ((Parcelable) v0);
    }

    public void setProgress(int arg7) {
        float v3 = 1f;
        int v0 = 100;
        if (arg7 > v0) {
            arg7 = v0;
        } else if (arg7 < 0) {
            arg7 = 0;
        }

        if (this.getAlpha() < v3) {
            this.animate().alpha(v3).setDuration(200).setInterpolator(this.a).start();
        }

        int v2 = this.getMeasuredWidth();
        this.e.left = 0;
        this.e.top = 0;
        this.e.bottom = this.getBottom() - this.getTop();
        if (arg7 < this.f && !this.g) {
            this.h = 0;
        } else if (arg7 == this.f && arg7 == v0) {
            this.a();
        }

        this.f = arg7;
        v0 = this.f * v2 / 100 - this.h;
        if (v0 != 0) {
            a v3_1 = new a(this, this.h, v0, v2);
            ((Animation) v3_1).setDuration(500);
            ((Animation) v3_1).setInterpolator(this.b);
            if (!this.c.isEmpty()) {
                this.c.add(v3_1);
            } else {
                this.startAnimation(((Animation) v3_1));
            }
        }
    }
}

